/*
* SmokeController.java
* Created on  202015/6/26 10:24
* �汾       �޸�ʱ��          ����      �޸�����
* V1.0.1    202015/6/26       longshihui    ��ʼ�汾
*
*/

package com.infitecs.eyas.enthalpy;

import com.infitecs.eyas.enthalpy.model.Air;
import com.infitecs.eyas.enthalpy.model.Smoke;
import com.infitecs.eyas.enthalpy.service.SmokeService;
import com.infitecs.eyas.session.model.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * @author longshihui
 * @version 1.0.1
 */
@Controller
@RequestMapping("/enthalpy/smoke")
public class SmokeController {

    @Autowired
    private SmokeService smokeService;

    @RequestMapping("")
    public String getPage(HttpSession session) {
        try {
            int caseId = Integer.parseInt(session.getAttribute("caseId").toString());
            if (smokeService.getSmoke(caseId) == null) {
                smokeService.addSmoke(caseId);
            }
        } catch (Exception e) {
            return "enthalpy/smoke";
        }
        return "enthalpy/smoke";
    }

    @RequestMapping(value = "/update/{Cx}", method = RequestMethod.POST)
    @ResponseBody
    public void updateGx(@PathVariable("Cx") String name, HttpServletRequest request, HttpSession session) {
        int caseId = Integer.parseInt(session.getAttribute("caseId").toString());
        Param param = new Param(name.trim());
        param.setParamValue(Double.parseDouble(request.getParameter(name)));
        param.setCaseId(caseId);
        smokeService.updateCx(param);
    }

    @RequestMapping(value = "/getSmoke", method = RequestMethod.POST)
    @ResponseBody
    public Smoke getAir(HttpSession session) {
        int caseId = Integer.parseInt(session.getAttribute("caseId").toString());
        return smokeService.getSmoke(caseId);
    }

    @RequestMapping(value = "/calculate/{Cx}", method = RequestMethod.POST)
    @ResponseBody
    public Double calCx(@PathVariable("Cx") String Cx, HttpSession session) {
        int caseId = Integer.parseInt(session.getAttribute("caseId").toString());
        Param param = new Param(Cx);
        param.setCaseId(caseId);
        switch (Cx) {
            case "C10":
                return smokeService.calC10(param);
        }
        return null;
    }
}
